#ifndef RUNSHOP_H
#define RUNSHOP_H

#include <QObject>
#include "QList"
#include "bean/citynode.h"
#include "persent/gamepersent.h"
#include "utils/gametask.h"
#include "QThread"
#include "utils/citymanager.h"
#include "QLineEdit"
#include "CallBack.h"
#include "QRunnable"
#include "bean/rolebean.h"
#include "bean/runshopgoods.h"
class  RunShop : public GamePersent,public CallBack,public QRunnable
{
    Q_OBJECT
public:
    int runStatue;
    explicit RunShop(QWidget *parent = nullptr);

    void initData(QList<RoleBean*> *roleBeans);


    bool setXiaoWeiPoint(QLineEdit *leXiaoweiPoint);
    bool setGroupIndex(QLineEdit *leGroupIndex);
    bool setRunshopGoodsPrice(QLineEdit *leBuyGoodsPrice);
    void callBack(QString str = "") override;
    bool isCancelTask() override;
    void run() override;
    ~RunShop();

private:
    QRectF qRectF;
    QThread *thread = nullptr;
    int runshopCount = 0; // 当前次数
    QMetaObject::Connection con;
    QList<RoleBean*> *roleBeans = nullptr;

    void goQianWeiYi();

    //帮派和城市之间跑商时，城市的商人
    void goRemoteMerchant();

    void leave(); //离开帮派

    void back(); //返回帮派

    void openShop(QString img);

    /**
     * @brief buy 买商品
     * @param img 商品图片url
     * @param start 商品掩码起始
     * @param end 商品掩码结束
     * @param count 商品数量
     */
    void buyCity(QString img, Scalar start, Scalar end, float threshold);


    void buyGoods(RunShopBean *runshop,bool isGroup, float threshold);

   //在对方帮派处卖商品
    void remoteSell(QString openShopImg);

    //在自己帮派处卖商品
     void groupSell(QString openShopImg);

    //帮派处领取银票
    void getBankNotes();
    //检查跑商是否跑满
    bool checkRunshopFill();

    //帮派处交还银票
    void giveBackBankNotes();

    //检查银票是否达到最大值
    bool checkYinPiaoBig();

    // 检查是否已经有银票
    bool checkHasYinPiao();
    //开通跑商路线
    bool checkHasRunshopLine();

    bool checkGoodsTime(QString goodsTime, RunShopGoods *goods);

    //开始跑商--去本帮
    void goGroup();
public slots:
    void  checkMove();

};

#endif // RUNSHOP_H
